using System.ComponentModel.DataAnnotations;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.Models;

/// <summary>
/// 日志配置映射
/// </summary>
public class LoggingConfiguration
{
    [Required]
    public LogLevelConfiguration LogLevel { get; set; } = new();
    
    public SecurityLogConfiguration SecurityLog { get; set; } = new();
    public AuditLogConfiguration AuditLog { get; set; } = new();
    public OperationLogConfiguration OperationLog { get; set; } = new();
    
    public bool EnableRequestResponseLogging { get; set; } = false;
}

/// <summary>
/// 日志级别配置
/// </summary>
public class LogLevelConfiguration
{
    public string Default { get; set; } = "Information";
    public string MicrosoftAspNetCore { get; set; } = "Warning";
}

/// <summary>
/// 安全日志配置
/// </summary>
public class SecurityLogConfiguration
{
    public bool Enabled { get; set; } = true;
    public string Level { get; set; } = "info";
    public string Path { get; set; } = "./logs/security.log";
    public string MaxSize { get; set; } = "10MB";
    public int MaxFiles { get; set; } = 10;
}

/// <summary>
/// 审计日志配置
/// </summary>
public class AuditLogConfiguration
{
    public bool Enabled { get; set; } = true;
    public string Path { get; set; } = "./logs/audit.log";
}

/// <summary>
/// 操作日志配置
/// </summary>
public class OperationLogConfiguration
{
    public bool Enabled { get; set; } = true;
    public string Path { get; set; } = "./logs/operation.log";
}

/// <summary>
/// Serilog 自定义配置
/// </summary>
public class SerilogCustConfiguration
{
    public bool ForceToEnable { get; set; } = true;
    public string DatabaseSerialType { get; set; } = "Postgres";
}

/// <summary>
/// Serilog 完整配置
/// </summary>
public class SerilogConfiguration
{
    public List<string> Using { get; set; } = new() { "Serilog.Sinks.Console", "Serilog.Sinks.File" };
    public SerilogMinimumLevelConfiguration MinimumLevel { get; set; } = new();
    public List<SerilogWriteToConfiguration> WriteTo { get; set; } = new();
    public List<string> Enrich { get; set; } = new() { "FromLogContext", "WithMachineName", "WithThreadId" };
}

/// <summary>
/// Serilog 最小级别配置
/// </summary>
public class SerilogMinimumLevelConfiguration
{
    public string Default { get; set; } = "Information";
    public Dictionary<string, string> Override { get; set; } = new()
    {
        ["Microsoft"] = "Warning",
        ["System"] = "Warning"
    };
}

/// <summary>
/// Serilog 写入配置
/// </summary>
public class SerilogWriteToConfiguration
{
    public string Name { get; set; } = string.Empty;
    public Dictionary<string, object> Args { get; set; } = new();
}
